<template>
  <div class="category">
    <h3>图书分类</h3>
    <div v-for="category in categories" :key="category.id">
      <h5>{{ category.name }}</h5>
      <router-link
        v-for="child in category.children"
        :key="child.id"
        :to="'/category/' + child.id"
        >{{ child.name }}</router-link
      >
    </div>
  </div>
</template>

<script>
export default {
  name: "HomeCategory",
  data() {
    return {
      categories: [],
    };
  },
  created() {
    this.axios
      .get("/category")
      .then((response) => {
        if (response.status == 200) {
          this.categories = response.data;
        }
      })
      .catch((error) => console.log(error));
  },
};
</script>

<style scoped>
.category {
  border: 1px solid #e0f3e4;
  width: 200px;
  text-align: center;
  margin: 0;
  border-radius: 10px;
  background: rgba(228, 227, 227, 0.144);
  transition: 0.8s;
}
.category:hover {
  box-shadow: 1px 1px 10px rgba(0, 0, 0, 0.356);
}
.category a {
  margin: 0 5px;
}
</style>
